from flask import Flask, request, jsonify
import logging
import time

# filename = "./" + time.strftime("%Y-%m-%d.log", time.localtime())

# logging.basicConfig(
#     level=logging.DEBUG,
#     filename=filename,
#     filemode="a",
#     format="%(asctime)s - %(levelname)s - %(message)s",
# )

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def home():
    print(request.args)  # GET: get parameters
    print(request.form)  # POST: get parameters
    return "<h1>Program is running</h1>"


@app.route("/json", methods=["POST"])
def json():
    print(request.json)  # Get dict object.
    # logging.info("Request" + request.url + " " + request.method)
    return jsonify({"status": True, "data": ["leslie", "moon", "michael"]})  # 结果的key一定要有引号


@app.route("/error")
def fail():
    # logging.info("Request" + request.url + " " + request.method)
    return "Error"


if __name__ == "__main__":
    app.run()
